import type { RoutingModel } from './models';

import { requestClient } from '#/api/request';

/**
 * 获取工艺路线数据集合
 * @param params 查询参数
 * @returns 返回查询结果
 */
export async function getRoutingListApi(params?: any) {
  return requestClient.get<RoutingModel[]>('/mes/process/routing/list', {
    params,
  });
}

/**
 * 分页查询工艺路线据集合
 * @param params 分页查询参数
 * @returns 返回查询结果
 */
export async function getRoutingPagedListApi(params?: PageParams) {
  return requestClient.get<PaginationResult<RoutingModel>>(
    '/mes/process/routing/list-page',
    {
      params,
    },
  );
}

/**
 * 创建工艺路线
 * @param data 要创建的工艺路线
 * @returns 返回结果
 */
export async function createRoutingApi(data: any) {
  return requestClient.post<boolean>('/mes/process/routing', data);
}

/**
 * 复制工艺路线
 * @param data 要复制的工艺路线
 * @returns 返回结果
 */
export async function copyRoutingApi(data: {
  fromRoutingId: number;
  toProductId: number;
  toRoutingCode: string;
  toRoutingName: string;
}) {
  return requestClient.post<boolean>('/mes/process/routing/copy', data);
}

/**
 * 更新工艺路线
 * @param id 工艺路线 Id
 * @param data 要更新的工艺路线
 * @returns 返回结果
 */
export async function updateRoutingApi(id: number, data: any) {
  return requestClient.put<boolean>(`/mes/process/routing/${id}`, data);
}

/**
 * 删除工艺路线
 * @param id 工艺路线 Id
 * @returns 返回结果
 */
export async function deleteRoutingApi(id: number) {
  return requestClient.delete<boolean>(`/mes/process/routing/${id}`);
}
